//
//  DailView.m
//  SHWheel
//
//  Created by YYKJ on 2020/9/3.
//  Copyright © 2020 YYKJ. All rights reserved.
//

#import "DailView.h"

@implementation DailView

- (void)drawRect:(CGRect)rect {
    
    CGFloat scaleWidth = 10.0f;
    CGFloat textWidth = 30.0f;
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGFloat radius = rect.size.width/2 - scaleWidth - textWidth;
    CGContextAddArc(ctx, rect.size.width/2, rect.size.height/2, radius, M_PI*0.75, M_PI*0.25, 0);
    
    for (int i=0; i<=10; i++) {
        CGContextMoveToPoint(ctx, rect.size.width/2-radius*cos(M_PI*0.75+M_PI*0.15*i), rect.size.height/2+radius*sin(M_PI*0.75+M_PI*0.15*i));
        CGContextAddLineToPoint(ctx, rect.size.width/2-(radius+scaleWidth)*cos(M_PI*0.75+M_PI*0.15*i), rect.size.height/2+(radius+scaleWidth)*sin(M_PI*0.75+M_PI*0.15*i));
        NSString *str = [NSString stringWithFormat:@"%d",100-i*10];
        CGPoint strPoint = CGPointMake(rect.size.width/2-(radius+scaleWidth+textWidth/2)*cos(M_PI*0.75+M_PI*0.15*i),
                                       rect.size.height/2+(radius+scaleWidth+textWidth/2)*sin(M_PI*0.75+M_PI*0.15*i));
        
        NSDictionary* stringAttrs = @{ NSFontAttributeName : [UIFont systemFontOfSize:16], NSForegroundColorAttributeName : [UIColor darkGrayColor] };
        NSAttributedString* attrStr = [[NSAttributedString alloc] initWithString:str attributes:stringAttrs];
        CGFloat strWidth = [str boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:16]} context:nil].size.width;

        [attrStr drawInRect:CGRectMake(strPoint.x-strWidth/2, strPoint.y-10, strWidth, 20)];
    }
    
    CGContextSetLineCap(ctx, kCGLineCapSquare);
    CGContextSetLineWidth(ctx, 1.0);
    CGContextSetStrokeColorWithColor(ctx, [UIColor darkGrayColor].CGColor);
    CGContextStrokePath(ctx);
}


@end
